export interface ListItem {
	title: string,
	url: string,
	desc: string,
	id: string
}

export interface State {
	list: ListItem[]
}


const initState: State = {
	list: []
}

const reducer = (state = initState, action: any) => {
	switch (action.type) {
		case 'ADD_USER_HISTORY': {
			return {
				...state,
				list: [action.payload, ...state.list.filter(v => v.id !== action.payload.id)]
			}
		}
		case 'SUB_USER_HISTORY': {
			return {
				...state,
				list: [...state.list].filter(v => v.id !== action.payload.id)
			}
		}
		default:
			return {
				...state
			}
	}
}


export default reducer